{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6068ab0d",
   "metadata": {
    "id": "6068ab0d"
   },
   "source": [
    "# voiGno Restaurant Agent – Voice Booking System with Interruption Handling"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "Y9FkDzt1lF47",
   "metadata": {
    "id": "Y9FkDzt1lF47"
   },
   "source": [
    "This notebook implements a conversational restaurant booking assistant using the Praison AI Agent framework. It handles natural interruptions such as modifying guest count or changing time mid-conversation. Built for Google Colab Free Tier, it uses OpenAI's gpt-5-nano model and follows a YAML-based agent design for clarity and modularity."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7Ik-GsSjlPza",
   "metadata": {
    "id": "7Ik-GsSjlPza"
   },
   "source": [
    "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/voiGno_Restaurant_Agent_PraisonAI.ipynb)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "vOsFg5C0lNg8",
   "metadata": {
    "id": "vOsFg5C0lNg8"
   },
   "source": [
    "# Dependencies"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c5b33646",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "c5b33646",
    "outputId": "3728c81a-e8f4-4fce-e2da-2723937df0b5"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[?25l   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/3.3 MB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r",
      "\u001b[2K   \u001b[91m━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.3/3.3 MB\u001b[0m \u001b[31m9.9 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r",
      "\u001b[2K   \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━━━━━━━━━━\u001b[0m \u001b[32m2.4/3.3 MB\u001b[0m \u001b[31m35.4 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r",
      "\u001b[2K   \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m32.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
      "\u001b[?25h"
     ]
    }
   ],
   "source": [
    "!pip install -q openai duckduckgo_search praisonaiagents"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5wUAjCAwlX-k",
   "metadata": {
    "id": "5wUAjCAwlX-k"
   },
   "source": [
    "# OpenAI API + Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c8dbd157",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "c8dbd157",
    "outputId": "2d9209c8-87a1-4093-bcbe-6f53b83867a1"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Enter your OpenAI API key: ··········\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "from getpass import getpass\n",
    "\n",
    "os.environ[\"OPENAI_API_KEY\"] = getpass(\"Enter your OpenAI API key: \")\n",
    "import openai\n",
    "from praisonaiagents import Agent, Task, PraisonAIAgents\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1qEN4kLNlcMq",
   "metadata": {
    "id": "1qEN4kLNlcMq"
   },
   "source": [
    "# YAML Prompt Configuration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7d20ac12",
   "metadata": {
    "id": "7d20ac12"
   },
   "outputs": [],
   "source": [
    "yaml_prompt = \"\"\"\n",
    "name: voiGnoRestaurantAgent\n",
    "role: Voice restaurant booking assistant with interruption handling\n",
    "goal: Coordinate bookings—date, time, guest count—with dynamic corrections\n",
    "backstory: You are a friendly, patient assistant that remembers and adapts conversation context.\n",
    "skills:\n",
    "  - Context management\n",
    "  - Handling mid-conversation changes\n",
    "  - Summarizing confirmed reservations\n",
    "llm: gpt-5-nano\n",
    "verbosity: true\n",
    "format: markdown\n",
    "\"\"\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "XcJsL2yple6S",
   "metadata": {
    "id": "XcJsL2yple6S"
   },
   "source": [
    "# Define Agent"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "jPfTEPRkkvl8",
   "metadata": {
    "id": "jPfTEPRkkvl8"
   },
   "outputs": [],
   "source": [
    "agent = Agent(\n",
    "    name=\"voiGnoRestaurantAgent\",\n",
    "    instructions=\"\"\"\n",
    "You are a restaurant booking assistant. Handle booking requests naturally,\n",
    "manage corrections like “change to 3 guests” or “move to 8 PM,”\n",
    "confirm the details once the user is satisfied. Respond in markdown.\n",
    "\"\"\",\n",
    "    llm=\"gpt-5-nano\",\n",
    "    verbose=True,\n",
    "    markdown=True\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "okUezUadlhl4",
   "metadata": {
    "id": "okUezUadlhl4"
   },
   "source": [
    "# Define Task"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e1de31ba",
   "metadata": {
    "id": "e1de31ba"
   },
   "outputs": [],
   "source": [
    "task = Task(\n",
    "    name=\"VoiceBookingTask\",\n",
    "    description=\"Assist user in making or updating a restaurant booking with interruptions.\",\n",
    "    expected_output=\"A markdown-style conversation confirming updated booking details.\",\n",
    "    agent=agent\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "TmgIxwgZlkI3",
   "metadata": {
    "id": "TmgIxwgZlkI3"
   },
   "source": [
    "# Build Agent System"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "1ca36e92",
   "metadata": {
    "id": "1ca36e92"
   },
   "outputs": [],
   "source": [
    "booking_system = PraisonAIAgents(\n",
    "    agents=[agent],\n",
    "    tasks=[task],\n",
    "    process=\"sequential\",\n",
    "    verbose=True\n",
    ")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "D-OG_N_0loEw",
   "metadata": {
    "id": "D-OG_N_0loEw"
   },
   "source": [
    "# Run Example Dialogue"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "A56Lhv0Lk5AT",
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 1000,
     "referenced_widgets": [
      "c605e612d0c9466e90451701534dac7b",
      "d77b8417c8c046fbb680d2f35c83a95b"
     ]
    },
    "id": "A56Lhv0Lk5AT",
    "outputId": "a8d64995-03c7-4faa-d08b-ce66757d47b4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "> You: I'd like to book a table for 2 at 7 PM tomorrow.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╭─ </span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8; font-weight: bold\">Agent Info</span><span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\"> ────────────────────────────────────────────────────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #ff9b9b; text-decoration-color: #ff9b9b; font-weight: bold\">👤 Agent:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">voiGnoRestaurantAgent</span>                                                                                <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>  <span style=\"color: #b4b4b3; text-decoration-color: #b4b4b3; font-weight: bold\">Role:</span> <span style=\"color: #ffe5e5; text-decoration-color: #ffe5e5\">Assistant</span>                                                                                                <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>                                                                                                                 <span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">│</span>\n",
       "<span style=\"color: #d2e3c8; text-decoration-color: #d2e3c8\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[38;2;210;227;200m╭─\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[1;38;2;210;227;200mAgent Info\u001b[0m\u001b[38;2;210;227;200m \u001b[0m\u001b[38;2;210;227;200m───────────────────────────────────────────────────────────────────────────────────────────────────\u001b[0m\u001b[38;2;210;227;200m─╮\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;255;155;155m👤 Agent:\u001b[0m \u001b[38;2;255;229;229mvoiGnoRestaurantAgent\u001b[0m                                                                                \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m  \u001b[1;38;2;180;180;179mRole:\u001b[0m \u001b[38;2;255;229;229mAssistant\u001b[0m                                                                                                \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m│\u001b[0m                                                                                                                 \u001b[38;2;210;227;200m│\u001b[0m\n",
       "\u001b[38;2;210;227;200m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "c605e612d0c9466e90451701534dac7b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Output()"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
      ],
      "text/plain": []
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #7f7f7f; text-decoration-color: #7f7f7f\">Response generated in 2.9s</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[2mResponse generated in 2.9s\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭───────────────────────────────────────────────────── Task ──────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> You need to do the following task: Assist user in making or updating a restaurant booking with interruptions..  <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> Expected Output: A markdown-style conversation confirming updated booking details.. Please provide only the     <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> final result of your work. Do not add any conversation or extra explanation.                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m────────────────────────────────────────────────────\u001b[0m\u001b[36m Task \u001b[0m\u001b[36m─────────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m You need to do the following task: Assist user in making or updating a restaurant booking with interruptions..  \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m Expected Output: A markdown-style conversation confirming updated booking details.. Please provide only the     \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m final result of your work. Do not add any conversation or extra explanation.                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008080; text-decoration-color: #008080\">╭─────────────────────────────────────────────────── Response ────────────────────────────────────────────────────╮</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"font-weight: bold\">Booking Confirmation</span>                                                                                            <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> Your restaurant booking has been successfully updated. Here are the details:                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> • </span><span style=\"font-weight: bold\">Date:</span> [Please specify the date]                                                                              <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> • </span><span style=\"font-weight: bold\">Time:</span> 8:00 PM                                                                                                <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> • </span><span style=\"font-weight: bold\">Guests:</span> 3                                                                                                    <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span>                                                                                                                 <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">│</span> If you need further assistance, feel free to ask!                                                               <span style=\"color: #008080; text-decoration-color: #008080\">│</span>\n",
       "<span style=\"color: #008080; text-decoration-color: #008080\">╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯</span>\n",
       "</pre>\n"
      ],
      "text/plain": [
       "\u001b[36m╭─\u001b[0m\u001b[36m──────────────────────────────────────────────────\u001b[0m\u001b[36m Response \u001b[0m\u001b[36m───────────────────────────────────────────────────\u001b[0m\u001b[36m─╮\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1mBooking Confirmation\u001b[0m                                                                                            \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m Your restaurant booking has been successfully updated. Here are the details:                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m • \u001b[0m\u001b[1mDate:\u001b[0m [Please specify the date]                                                                              \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m • \u001b[0m\u001b[1mTime:\u001b[0m 8:00 PM                                                                                                \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m \u001b[1;33m • \u001b[0m\u001b[1mGuests:\u001b[0m 3                                                                                                    \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m                                                                                                                 \u001b[36m│\u001b[0m\n",
       "\u001b[36m│\u001b[0m If you need further assistance, feel free to ask!                                                               \u001b[36m│\u001b[0m\n",
       "\u001b[36m╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "**Booking Confirmation**\n",
      "\n",
      "Your restaurant booking has been successfully updated. Here are the details:\n",
      "\n",
      "- **Date:** [Please specify the date]\n",
      "- **Time:** 8:00 PM\n",
      "- **Guests:** 3\n",
      "\n",
      "If you need further assistance, feel free to ask! \n",
      "\n",
      "> You: Wait, actually make that 3 people instead.\n",
      "**Booking Confirmation**\n",
      "\n",
      "Your restaurant booking has been successfully updated. Here are the details:\n",
      "\n",
      "- **Date:** [Please specify the date]\n",
      "- **Time:** 8:00 PM\n",
      "- **Guests:** 3\n",
      "\n",
      "If you need further assistance, feel free to ask! \n",
      "\n",
      "> You: Can we move it to 8 PM?\n",
      "**Booking Confirmation**\n",
      "\n",
      "Your restaurant booking has been successfully updated. Here are the details:\n",
      "\n",
      "- **Date:** [Please specify the date]\n",
      "- **Time:** 8:00 PM\n",
      "- **Guests:** 3\n",
      "\n",
      "If you need further assistance, feel free to ask! \n",
      "\n",
      "> You: Great, that's perfect!\n",
      "**Booking Confirmation**\n",
      "\n",
      "Your restaurant booking has been successfully updated. Here are the details:\n",
      "\n",
      "- **Date:** [Please specify the date]\n",
      "- **Time:** 8:00 PM\n",
      "- **Guests:** 3\n",
      "\n",
      "If you need further assistance, feel free to ask! \n",
      "\n"
     ]
    }
   ],
   "source": [
    "dialog = [\n",
    "    \"I'd like to book a table for 2 at 7 PM tomorrow.\",\n",
    "    \"Wait, actually make that 3 people instead.\",\n",
    "    \"Can we move it to 8 PM?\",\n",
    "    \"Great, that's perfect!\"\n",
    "]\n",
    "\n",
    "for turn in dialog:\n",
    "    print(f\"> You: {turn}\")\n",
    "    response = booking_system.start(input=turn)\n",
    "    print(response, \"\\n\")\n"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
